package com.jessechanrui.template.req15;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.itextpdf.text.pdf.draw.LineSeparator;
import javafx.scene.text.Text;

import javax.imageio.ImageIO;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.codehaus.plexus.util.FileUtils;

import sun.java2d.pipe.CompositePipe;
import sun.java2d.pipe.TextRenderer;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.EncodeHintType;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.agree.bos.bpbc.service.IBpbcPdfSerevice;
import com.agree.bos.nsh.model.AfaCzedxzpTxnjnl;
import com.agree.bos.nsh.service.IBlackAshListSerevice;
import com.agree.framework.dao.entity.Page;
import com.agree.framework.exception.AppException;
import com.agree.framework.web.service.base.BaseService;
import com.agree.util.DateUtil;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Font.FontFamily;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;
//import com.itextpdf.text.pdf.qrcode.BitMatrix;
//import com.itextpdf.text.pdf.qrcode.EncodeHintType;
//import com.itextpdf.text.pdf.qrcode.ErrorCorrectionLevel;

public class BpbcPdfSerevice extends BaseService implements IBpbcPdfSerevice{
	private Logger logger = Logger.getLogger(BpbcPdfSerevice.class);


	/**
	 * @category BEC_SCPDF 银行函证PDF生成
	 * @param busidate
	 *            入参|业务日期|{@link String}
	 * @param confirmno 
	 *            入参|函证编号|{@link String}
	 * @param tenantname
	 *            入参|会计师事务所名称|{@link String}
	 * @param enddate
	 *            入参|截止日期|{@link String}
	 * @param organizationname           
	 *            入参|单位名称|{@link String}
	 * @param values
	 *            入参|函证项信息|{@link cn.com.agree.afa.svc.javaengine.context.JavaList}
	 * @param outputfilePath
	 *            入参|PDF存放文件路径|{@link String}
	 * @since error 出参|PDF生成结果true/false|{@link String}
	 * @return 0 失败<br/>
	 *         1 成功<br/>
	 * @throws DocumentException 
	 * @throws IOException 
	 */
	@Override
	public boolean createPdf(JSONObject json) throws Exception {
		//AppLogger.info("业务日期---------：" + busi_date);
		//AppLogger.info("函证编号---------：" + confirmno);
		//AppLogger.info("会计师事务所名称---------：" + tenantname);
		//AppLogger.info("起始日期---------：" + startdate);
		//AppLogger.info("截止日期---------：" + enddate);
		//AppLogger.info("单位名称---------：" + organizationname);
		//AppLogger.info("函证项信息---------：" + String.valueOf(values));
		
		//*************************生成PDF文件
		//AppLogger.info("*************************生成PDF文件start");
		String hzbh = (String) json.get("hzbh");//函证编号
		String recvdate = (String) json.get("recvdate");//函证接收日期
		String organizationname = (String) json.get("organizationname");//单位名称
		String tenantname = (String) json.get("tenantname");//会计师事务所名称
//		System.out.print("函证编号---------：" + hzbh);
//		System.out.print("函证编号---------：" + json);
		String sendhzno = (String) json.get("sendhzno");//20240710发函编号
		
		
		String confirmbegindate = (String) json.get("confirmbegindate");//起始日期
		String confirmenddate = (String) json.get("confirmenddate");//截止日期
		
		String pdffilepath = (String) json.get("pdffilepath");
		String finishdate = (String) json.get("finishdate");
		
//		Date Date = new Date();
//		SimpleDateFormat format_s = new SimpleDateFormat("yyyyMMdd");
		String workdate=finishdate;
		//String workdate = (String) json.get("workdate");
		
		String agent = (String) json.get("agent");//经办人
		String reviewer = (String) json.get("reviewer");//审核人
		
		int agentLength = agent.getBytes().length;
		logger.error("agentLength:"+agentLength);
		int reviewerLength = reviewer.getBytes().length;
		logger.error("reviewerLength:"+reviewerLength);
		
		if(agentLength<=60){
			for(int i = agent.length(); i <= 60; i++){
				agent = agent + " ";
			}
		}
		if(reviewerLength<=60){
			for(int i = reviewer.length(); i <= 60; i++){
				reviewer = reviewer + " ";
			}
		}
		logger.info("经办人["+agent+"]");
		logger.info("复核人["+reviewer+"]");
		
		//页面大小
		String startdate;
		String busi_date = null;
		Rectangle rect = new Rectangle(PageSize.A4);//文档竖向
//		String outputfilePath = "C:/Users/A9010012/Desktop";
		String outputfilePath = pdffilepath+hzbh+"_0.pdf";
		
		Document doc = null;
		PdfWriter writer= null;
		try{
			//如果没有则创建
			File saveDir = new File(outputfilePath);
			File dir = saveDir.getParentFile();
			if(!dir.exists()){
				dir.mkdirs();			
			}
			doc = new Document(rect);
			writer= PdfWriter.getInstance(doc, new FileOutputStream(outputfilePath));
			//writer.setViewerPreferences(PdfWriter.PageLayoutOneColumn);
			//writer.setPageEvent(new PdfPageEventHelper());
			//PDF版本（默认1.4）
			writer.setPdfVersion(PdfWriter.VERSION_1_7);
			//页边空白	
			doc.setMargins(40, 40, 40, 40);
			//打开文档
			doc.open();
			
			//AppLogger.info("-***********************生成PDF文件end");
			//*********************************************添加PDF文件头
			//doc.add(getFont(6, "Confidential 机密                                                                                          "+"发函编号："+sendhzno));
			//doc.add(getFont(6, "Confidential 机密"));
//			if(sendhzno.equals("")){
//				sendhzno = "无";
//			}
			//doc.add(getFont(5, "发函编号："+sendhzno));
			doc.add(getFont(1, "银行询证函"));
			//doc.add(getFont(4, "编号："+hzbh));
			doc.add(getFont(3, tenantname+"会计师事务所："));
			doc.add(getFont(3, "贵方编号："+sendhzno));
			doc.add(getFont(3, "我行编号："+hzbh));
			doc.add(getFont(3, "截至"+confirmenddate+"，"+organizationname+"单位的询证信息如下："));
			
//			boolean flag_6 = false;
//			List values = new ArrayList();
//			values.add("1");

			if(json != null && !json.equals("{}")){
				PdfPTable table = null;
//				List result = null;
				//银行存款函证
				List bankdeposit_colName = Arrays.asList("账户名称","银行账号","币种","利率","账户类型","账户余额","是否属于资金归集（资金池或其他资金管理）账户","起始日期","终止日期","是否存在冻结、担保或其他使用限制（如是，请注明相关情形）","备注");//
				//银行借款函证
				List bankloan_colName = Arrays.asList("借款人名称","借款账号","币种","余额","借款日期","到期日期","利率","抵（质）押品/担保人","备注");
				//期间注销账户函证
				List closeacctno_colName = Arrays.asList("账户名称","银行账号","币种","注销账户日");
				//公司贷款方委托贷款函证
				List creditloan_colName = Arrays.asList("账户名称","银行结算账号/借据编号/贷款账号","资金借入方","币种","利率","余额","贷款起止日期","备注");//
				//公司借款方委托贷款函证
				List debtorloan_colName = Arrays.asList("账户名称","银行结算账号/借据编号/贷款账号","资金借出方","币种","利率","余额","贷款起止日期","备注");//
				//银行受益人担保函证
				List ensurefavoree_colName = Arrays.asList("被担保人","担保方式","币种","担保余额","担保到期日","担保合同编号","备注");
				//银行担保函证
				List givesecurity_colName = Arrays.asList("被担保人","担保方式","币种","担保金额","担保到期日","担保合同编号","备注");
				//未支付银行承兑汇票函证
				List unpaidaccance_colName = Arrays.asList("银行承兑汇票号码","结算账户账号","币种","票面金额","出票日","到期日","抵（质）押品");
				//未到期商业汇票函证
				List notduetradebill_colName = Arrays.asList("商业汇票号码","承兑人名称","币种","票面金额","出票日","到期日","贴现日","贴现率","贴现净额");
				//银行托收商业汇票函证
				List colltradebill_colName = Arrays.asList("商业汇票号码","承兑人名称","币种","票面金额","出票日","到期日");
				//不可撤销信用证函证
				List irrofcredit_colName = Arrays.asList("信用证号码","受益人","币种","信用证金额","到期日","未使用金额");
				//外汇买卖合约函证
				List foreigndealcon_colName = Arrays.asList("类    别","合约号码","贵行卖出币种","贵行买入币种","未履行的合约买卖金额","汇率","交收日期");
				//证券产权文件函证
				List secquityfile_colName = Arrays.asList("证券或其他产权文件名称","证券代码或产权文件编号","数量","币种","金额");
				//未到期银行理财产品函证
				List notduefinalpro_colName = Arrays.asList("产品名称","产品类型（封闭式/开放式）","币种","持有份额","产品净值","购买日","到期日","是否被用于担保或存在其他使用限制");
				//资金归集账户信息函证
				List cashconacctinfo_colName = Arrays.asList("序号","资金提供机构名称(即拨入资金的具体机构)","资金提供机构账号","资金使用机构名称(即向该具体机构拨出资金)","资金使用机构账号","币种","截至函证基准日拨入或拨出资金余额(拨出填列正数，拨入填列负数)","备注");
				//其他函证
				List otherinfo_colName = Arrays.asList("无");
				
				//其他函证1
				List otherinfo1_colName = Arrays.asList("客户名称","类别","合约号码","贵行支付币种","贵行收取币种","未履行的合约金额","到期日");
				//其他函证2
				List otherinfo2_colName = Arrays.asList("客户名称","类别","合约号码","期权结构","未履行的合约币种","未履行的合约金额","行权价格","到期日");
				//其他函证3
				List otherinfo3_colName = Arrays.asList("客户名称","类别","合约号码","贵行支付利率","贵行收取利率","未履行的合约币种","未履行的合约金额","到期日");
				//其他函证4
				List otherinfo4_colName = Arrays.asList("客户名称","类别","合约号码","期权结构","未履行的合约币种","未履行的合约金额","行权价格","到期日");
				
				//其他函证5
				List otherinfo5_colName = Arrays.asList("借款人名称","借款账号","币种","余额","借款日期","到期日期","利率","抵(质)押品担保人","备注");
				
				//其他函证6
				List otherinfo6_colName = Arrays.asList("除上述列示的其他信息外，本行补充以下信息");
				
				System.out.print(json.get("bankdeposit_num"));
				
				for (int i = 0; i < (int)json.get("hzxnum"); i++) {
					List a = (List)json.get("hzxinfo");
					
//					System.out.print("******"+a.get(i).toString().replace("[", "").replace("]", "").replace("\"", ""));
//					System.out.print("******"+a.get(i).toString().replace("[", "").replace("]", "").replace("\"", ""));
//					switch(a.get(i).toString().replace("[", "").replace("]", "").replace("\"", "")){
					switch(a.get(i).toString()){
						case "[\"1\"]":
							if((int)json.get("bankdeposit_num") > 0){
								List result = (List)json.get("bankdeposit");
								System.out.print(result.toString());
								table = tableTemplates(result,bankdeposit_colName);
								doc.add(getFont(3, "1.银行存款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行存款（包括余额为零的存款账户）外，本公司并无在贵行的其他存款。"));	
							}else if((int)json.get("bankdeposit_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < bankdeposit_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								table = tableTemplates(result,bankdeposit_colName);
								doc.add(getFont(3, "1.银行存款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行存款（包括余额为零的存款账户）外，本公司并无在贵行的其他存款。"));
							}
						break;
						case "[\"2\"]":
							if((int)json.get("bankloan_num") > 0){
								List result = (List)json.get("bankloan");
								System.out.print(result.toString());
								table = tableTemplates(result,bankloan_colName);
								doc.add(getFont(3, "2.银行借款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行借款外，本公司并无自贵行的其他借款。"));	
							}else if((int)json.get("bankloan_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < bankloan_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print("=========="+result);
								table = tableTemplates(result,bankloan_colName);
								doc.add(getFont(3, "2.银行借款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行借款外，本公司并无自贵行的其他借款。"));
							}
						break;
						case "[\"3\"]"://
							if((int)json.get("closeacctno_num") > 0){
								String begdate = DateUtil.formatDate(confirmbegindate, "yyyymmdd", "yyyy年mm月dd日");
								String enddate = DateUtil.formatDate(confirmenddate, "yyyymmdd", "yyyy年mm月dd日");
								List result = (List)json.get("closeacctno");
								table = tableTemplates(result,closeacctno_colName);
								doc.add(getFont(3, "3.自"+begdate+"起至"+enddate+"期间内注销的银行存款账户"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的注销账户外，本公司在此期间并未在贵行注销其他账户。"));	
							}else if((int)json.get("closeacctno_num") == 0){
								String begdate = DateUtil.formatDate(confirmbegindate, "yyyymmdd", "yyyy年mm月dd日");
								String enddate = DateUtil.formatDate(confirmenddate, "yyyymmdd", "yyyy年mm月dd日");
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < closeacctno_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,closeacctno_colName);
								doc.add(getFont(3, "3.自"+begdate+"起至"+enddate+"期间内注销的银行存款账户"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的注销账户外，本公司在此期间并未在贵行注销其他账户。"));
							}
						break;
						case "[\"4\"]":
							if((int)json.get("creditloan_num") > 0){
								
								List result = (List)json.get("creditloan");
								table = tableTemplates(result,creditloan_colName);
								doc.add(getFont(3, "4.本公司作为委托人的委托贷款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的委托贷款外，本公司并无通过贵行办理的其他以本公司作为委托人的委托贷款。"));	
							}else if((int)json.get("creditloan_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < creditloan_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,creditloan_colName);
								doc.add(getFont(3, "4.本公司作为委托人的委托贷款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的委托贷款外，本公司并无通过贵行办理的其他以本公司作为委托人的委托贷款。"));
							}
						break;
						case "[\"5\"]":
							if((int)json.get("debtorloan_num") > 0){
								
								List result = (List)json.get("debtorloan");
								table = tableTemplates(result,debtorloan_colName);
								doc.add(getFont(3, "5.本公司作为借款人的委托贷款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的委托贷款外，本公司并无通过贵行办理的其他以本公司作为借款人的委托贷款。"));	
							}else if((int)json.get("debtorloan_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < debtorloan_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,debtorloan_colName);
								doc.add(getFont(3, "5.本公司作为借款人的委托贷款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的委托贷款外，本公司并无通过贵行办理的其他以本公司作为借款人的委托贷款。"));
							}
						break;
						case "[\"6.1\"]":
							if((int)json.get("ensurefavoree_num") > 0){
								
								List result = (List)json.get("ensurefavoree");
								table = tableTemplates(result,ensurefavoree_colName);
								doc.add(getFont(3, "6.担保"));
					      		doc.add(getFont(3, "（1）本公司为其他单位提供的、以贵行为担保受益人的担保"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的担保外，本公司并无其他以贵行为担保受益人的担保。"));	
							}else if((int)json.get("ensurefavoree_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < ensurefavoree_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,ensurefavoree_colName);
								doc.add(getFont(3, "6.担保"));
					      		doc.add(getFont(3, "（1）本公司为其他单位提供的、以贵行为担保受益人的担保"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的担保外，本公司并无其他以贵行为担保受益人的担保。"));
							}
						break;
						case "[\"6.2\"]":
							if((int)json.get("givesecurity_num") > 0){
								
								List result = (List)json.get("givesecurity");
								table = tableTemplates(result,givesecurity_colName);
								doc.add(getFont(3, "6.担保"));
					       		doc.add(getFont(3, "（2）贵行向本公司提供的担保（如保函业务、备用信用证业务等）")); 
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的担保外，本公司并无贵行提供的其他担保。"));	
							}else if((int)json.get("givesecurity_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < givesecurity_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,givesecurity_colName);
								doc.add(getFont(3, "6.担保"));
					       		doc.add(getFont(3, "（2）贵行向本公司提供的担保（如保函业务、备用信用证业务等）")); 
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的担保外，本公司并无贵行提供的其他担保。"));
							}
						break;
						case "[\"7\"]":
							if((int)json.get("unpaidaccance_num") > 0){
								
								List result = (List)json.get("unpaidaccance");
								table = tableTemplates(result,unpaidaccance_colName);
								doc.add(getFont(3, "7.本公司为出票人且由贵行承兑而尚未支付的银行承兑汇票"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行承兑汇票外，本公司并无由贵行承兑而尚未支付的其他银行承兑汇票。"));	
							}else if((int)json.get("unpaidaccance_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < unpaidaccance_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,unpaidaccance_colName);
								doc.add(getFont(3, "7.本公司为出票人且由贵行承兑而尚未支付的银行承兑汇票"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行承兑汇票外，本公司并无由贵行承兑而尚未支付的其他银行承兑汇票。"));
							}
						break;
						case "[\"8\"]":
							if((int)json.get("notduetradebill_num") > 0){
								
								List result = (List)json.get("notduetradebill");
								table = tableTemplates(result,notduetradebill_colName);
								doc.add(getFont(3, "8.本公司向贵行已贴现而尚未到期的商业汇票"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的商业汇票外，本公司并无向贵行已贴现而尚未到期的其他商业汇票。"));	
							}else if((int)json.get("notduetradebill_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < notduetradebill_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,notduetradebill_colName);
								doc.add(getFont(3, "8.本公司向贵行已贴现而尚未到期的商业汇票"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的商业汇票外，本公司并无向贵行已贴现而尚未到期的其他商业汇票。"));
							}
						break;
						case "[\"9\"]"://
							if((int)json.get("colltradebill_num") > 0){
								
								List result = (List)json.get("colltradebill");
								table = tableTemplates(result,colltradebill_colName);
								doc.add(getFont(3, "9.本公司为持票人且由贵行托收（或由本公司提示付款）的商业汇票"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的商业汇票外，本公司并无由贵行托收的其他商业汇票。"));	
							}else if((int)json.get("colltradebill_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < colltradebill_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,colltradebill_colName);
								doc.add(getFont(3, "9.本公司为持票人且由贵行托收（或由本公司提示付款）的商业汇票"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的商业汇票外，本公司并无由贵行托收的其他商业汇票。"));
							}
						break;
						case "[\"10\"]":
							if((int)json.get("irrofcredit_num") > 0){
								
								List result = (List)json.get("irrofcredit");
								table = tableTemplates(result,irrofcredit_colName);
								doc.add(getFont(3, "10.本公司为申请人，由贵行开具的、未履行完毕的不可撤销信用证"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的不可撤销信用证外，本公司并无由贵行开具的、未履行完毕的其他不可撤销信用证。"));	
							}else if((int)json.get("irrofcredit_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < irrofcredit_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,irrofcredit_colName);
								doc.add(getFont(3, "10.本公司为申请人，由贵行开具的、未履行完毕的不可撤销信用证"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的不可撤销信用证外，本公司并无由贵行开具的、未履行完毕的其他不可撤销信用证。"));
							}
						break;
						case "[\"11\"]":
							if((int)json.get("foreigndealcon_num") > 0){
								
								List result = (List)json.get("foreigndealcon");
								table = tableTemplates(result,foreigndealcon_colName);
								doc.add(getFont(3, "11.本公司与贵行之间未履行完毕的外汇买卖合约"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的外汇买卖合约外，本公司并无与贵行之间未履行完毕的其他外汇买卖合约。"));	
							}else if((int)json.get("foreigndealcon_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < foreigndealcon_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,foreigndealcon_colName);
								doc.add(getFont(3, "11.本公司与贵行之间未履行完毕的外汇买卖合约"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的外汇买卖合约外，本公司并无与贵行之间未履行完毕的其他外汇买卖合约。"));
							}
						break;
						case "[\"12\"]":
							if((int)json.get("secquityfile_num") > 0){
								
								List result = (List)json.get("secquityfile");
								table = tableTemplates(result,secquityfile_colName);
								doc.add(getFont(3, "12.本公司存放于贵行托管的证券或其他产权文件"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的证券或其他产权文件外，本公司并无存放于贵行托管的其他证券或其他产权文件。"));	
							}else if((int)json.get("secquityfile_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < secquityfile_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,secquityfile_colName);
								doc.add(getFont(3, "12.本公司存放于贵行托管的证券或其他产权文件"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的证券或其他产权文件外，本公司并无存放于贵行托管的其他证券或其他产权文件。"));
							}
						break;
						case "[\"13\"]":
							if((int)json.get("notduefinalpro_num") > 0){
								
								List result = (List)json.get("notduefinalpro");
								table = tableTemplates(result,notduefinalpro_colName);
								doc.add(getFont(3, "13.本公司购买的由贵行发行的未到期银行理财产品"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行理财产品外，本公司并未购买其他由贵行发行的理财产品。"));	
							}else if((int)json.get("notduefinalpro_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < notduefinalpro_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,notduefinalpro_colName);
								doc.add(getFont(3, "13.本公司购买的由贵行发行的未到期银行理财产品"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行理财产品外，本公司并未购买其他由贵行发行的理财产品。"));
							}
						break;
						case "[\"14\"]":
							if((int)json.get("otherinfo_num") > 0){
								List result = (List)json.get("otherinfo");
								table = tableTemplates(result,otherinfo_colName);
								doc.add(getFont(3, "14.其他"));
								doc.add(table);
								
							}else if((int)json.get("otherinfo_num") == 0){
								PdfPTable table_other = null;
								PdfPTable table_other_none = null;
								
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < otherinfo_colName.size()+1; j++) {
									li.add("	");
								}
								result.add(li);
								List result_zore = new ArrayList();
								List li_zore = new ArrayList();
								for (int j = 1; j < otherinfo_colName.size()+1; j++) {
									li_zore.add("无");
								}
								result_zore.add(li_zore);
//								List result_none = new ArrayList();
//								List li_none = new ArrayList();
//								for (int j = 1; j < otherinfo_colName.size()+1; j++) {
//									li_none.add("无");
//								}
//								result.add(li);
								
								table_other_none = tableTemplates(result,otherinfo_colName);
								doc.add(getFont(3, "14.其他"));
								//doc.add(table_other);
								if((int)json.get("otherinfo1_num") == 0 && (int)json.get("otherinfo2_num") == 0 && (int)json.get("otherinfo3_num") == 0 && (int)json.get("otherinfo4_num") == 0 && (int)json.get("otherinfo5_num") == 0 && (int)json.get("otherinfo6_num") == 0){
									table_other = tableTemplates(result_zore,otherinfo_colName);
									doc.add(table_other);
								}else{
									if((int)json.get("otherinfo1_num") > 0){
										List result1 = (List)json.get("otherinfo1");
										table_other = tableTemplates(result1,otherinfo1_colName);
										doc.add(table_other);
									}else if((int)json.get("otherinfo1_num") == 0){
										List result_otherinfo1 = new ArrayList();
										List result1 = new ArrayList();
										List li1 = new ArrayList();
										for (int j = 1; j < otherinfo1_colName.size()+1; j++) {
											li1.add("无");
										}
										result1.add(li1);
										table_other = tableTemplates(result1,otherinfo1_colName);
										doc.add(table_other);
										
									}
									doc.add(table_other_none);
									if((int)json.get("otherinfo2_num") > 0){
										List result2 = (List)json.get("otherinfo2");
										table_other = tableTemplates(result2,otherinfo2_colName);
										doc.add(table_other);
									}else if((int)json.get("otherinfo2_num") == 0){
										List result_otherinfo2 = new ArrayList();
										List result2 = new ArrayList();
										List li2 = new ArrayList();
										for (int j = 1; j < otherinfo2_colName.size()+1; j++) {
											li2.add("无");
										}
										result2.add(li2);
										table_other = tableTemplates(result2,otherinfo2_colName);
										doc.add(table_other);
									}
									doc.add(table_other_none);
									if((int)json.get("otherinfo3_num") > 0){
										List result3 = (List)json.get("otherinfo3");
										table_other = tableTemplates(result3,otherinfo3_colName);
										doc.add(table_other);
									}else if((int)json.get("otherinfo3_num") == 0){
										List result_otherinfo3 = new ArrayList();
										List result3 = new ArrayList();
										List li3 = new ArrayList();
										for (int j = 1; j < otherinfo3_colName.size()+1; j++) {
											li3.add("无");
										}
										result3.add(li3);
										table_other = tableTemplates(result3,otherinfo3_colName);
										doc.add(table_other);
									}
									doc.add(table_other_none);
									if((int)json.get("otherinfo4_num") > 0){
										List result4 = (List)json.get("otherinfo4");
										table_other = tableTemplates(result4,otherinfo4_colName);
										doc.add(table_other);
									}else if((int)json.get("otherinfo4_num") == 0){
										List result_otherinfo4 = new ArrayList();
										List result4 = new ArrayList();
										List li4 = new ArrayList();
										for (int j = 1; j < otherinfo4_colName.size()+1; j++) {
											li4.add("无");
										}
										result4.add(li4);
										table_other = tableTemplates(result4,otherinfo4_colName);
										doc.add(table_other);
									}
									doc.add(table_other_none);
									if((int)json.get("otherinfo5_num") > 0){
										List result5 = (List)json.get("otherinfo5");
										table_other = tableTemplates(result5,otherinfo5_colName);
										doc.add(table_other);
									}else if((int)json.get("otherinfo5_num") == 0){
										List result_otherinfo5 = new ArrayList();
										List result5 = new ArrayList();
										List li5 = new ArrayList();
										for (int j = 1; j < otherinfo5_colName.size()+1; j++) {
											li5.add("无");
										}
										result5.add(li5);
										table_other = tableTemplates(result5,otherinfo5_colName);
										doc.add(table_other);
									}	
									doc.add(table_other_none);
									if((int)json.get("otherinfo6_num") > 0){
										List result6 = (List)json.get("otherinfo6");
										table_other = tableTemplates(result6,otherinfo6_colName);
										doc.add(table_other);
									}else if((int)json.get("otherinfo6_num") == 0){
										List result_otherinfo6 = new ArrayList();
										List result6 = new ArrayList();
										List li6 = new ArrayList();
										for (int j = 1; j < otherinfo6_colName.size()+1; j++) {
											li6.add("无");
										}
										result6.add(li6);
										table_other = tableTemplates(result6,otherinfo6_colName);
										doc.add(table_other);
									}	
								}
								
								
								
								
								
								
//					       		doc.add(getFont(2, "除上述列示的委托贷款外，本公司并无通过贵行办理的其他以本公司作为委托人的委托贷款。"));
							}
						break;
						case "[\"15\"]":
							if((int)json.get("cashconacctinfo_num") > 0){
								
								List result = (List)json.get("cashconacctinfo");
								table = tableTemplates(result,cashconacctinfo_colName);
								doc.add(getFont(3, "附表.资金归集(资金池或其他资金管理)账户具体信息"));
								doc.add(table);
//					       		doc.add(getFont(2, "除上述列示的委托贷款外，本公司并无通过贵行办理的其他以本公司作为委托人的委托贷款。"));	
							}else if((int)json.get("cashconacctinfo_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < cashconacctinfo_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,cashconacctinfo_colName);
								doc.add(getFont(3, "附表.资金归集(资金池或其他资金管理)账户具体信息"));
								doc.add(table);
//					       		doc.add(getFont(2, "除上述列示的委托贷款外，本公司并无通过贵行办理的其他以本公司作为委托人的委托贷款。"));
							}
						break;
					}

					
				}
			}
			//doc.add(getFont(5, "\r\n\r\n\r\n"));
//			doc.add(getFont(5, "\r\n\r\n"));
//	        //doc.add(getFont(5, "银行签章（加盖电子业务专用章）\r\n\r\n"));
//	        //doc.add(getFont(5, "银行签章（加盖询证函业务专用章）\r\n\r\n"));
//	        //doc.add(getFont(5, "签署日期："+workdate+"\r\n"));
////	      doc.add(getFont(5, "二维码（验证函证内容）"));
//			
//			
//			doc.add(getFont(3, "本行确认在上述第1-14项及附表（如适用）的表格中填列的金额和信息是正确、完整的。\r\n\r\n\r\n\r\n"));
////			doc.add(getFont(4, "经办人："+agent+"                                                            银行签章           \r\n\r\n"));
////			doc.add(getFont(4, "复核人："+reviewer+"                                                            签署日期："+workdate+"\r\n"));
//			doc.add(getFont(4, "经办人："+agent+"银行签章             \r\n\r\n"));
//			doc.add(getFont(4, "复核人："+reviewer+"签署日期：  "+workdate+"\r\n"));
			
			/**说明：
			1、基于客户的询证需求，我行按贵方来函询证项目进行回函，如有疑问，请及时与我行联系。
			2、本询证函回函中所列信息应严格保密，仅用于来函指定目的，我行不承担任何形式的担保责任。**/
			float currentY = writer.getVerticalPosition(true);
			logger.error("文件高度："+currentY);
			float remainingHeight = currentY - doc.bottomMargin();
			logger.error("剩余高度："+remainingHeight);
			float lineHeight = new Phrase("test",new Font(FontFamily.HELVETICA,12)).getLeading();
			logger.error("行高："+lineHeight);
			int remainingLines = (int) (remainingHeight/lineHeight);
			logger.error("剩余行数："+remainingLines);
			
			if (remainingLines > 10) {
				logger.error("Line>10");
				doc.add(getFont(3, "本行确认在上述第1-14项及附表（如适用）的表格中填列的金额和信息是正确、完整的。\r\n\r\n\r\n\r\n"));
//				doc.add(getFont(4, "经办人："+agent+"                                                            银行签章           \r\n\r\n"));
//				doc.add(getFont(4, "复核人："+reviewer+"                                                            签署日期："+workdate+"\r\n"));
				doc.add(getFont(4, "经办人："+agent+"银行签章             \r\n\r\n"));
				doc.add(getFont(4, "复核人："+reviewer+"签署日期：  "+workdate+"\r\n"));
			} else {
				logger.error("Line<10");
				for(int linenumber = 0;linenumber < remainingLines-3;linenumber++){
					logger.error("blank line");
					doc.add(getFont(5, "\r\n"));
				}
				doc.add(getFont(3, "本行确认在上述第1-14项及附表（如适用）的表格中填列的金额和信息是正确、完整的。\r\n\r\n\r\n\r\n"));
//				doc.add(getFont(4, "经办人："+agent+"                                                            银行签章           \r\n\r\n"));
//				doc.add(getFont(4, "复核人："+reviewer+"                                                            签署日期："+workdate+"\r\n"));
				doc.add(getFont(4, "经办人："+agent+"银行签章             \r\n\r\n"));
				doc.add(getFont(4, "复核人："+reviewer+"签署日期：  "+workdate+"\r\n"));
			}
	       // createFooter(pdffilepath+hzbh+".pdf",pdffilepath+hzbh+"_1.pdf");
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			doc.close();
	        writer.close();
		}
		

        
		return true;	
				
	}
	/**
	 * @category BEC_SCPDF 银行函证PDF生成
	 * @param busidate
	 *            入参|业务日期|{@link String}
	 * @param confirmno 
	 *            入参|函证编号|{@link String}
	 * @param tenantname
	 *            入参|会计师事务所名称|{@link String}
	 * @param enddate
	 *            入参|截止日期|{@link String}
	 * @param organizationname           
	 *            入参|单位名称|{@link String}
	 * @param values
	 *            入参|函证项信息|{@link cn.com.agree.afa.svc.javaengine.context.JavaList}
	 * @param outputfilePath
	 *            入参|PDF存放文件路径|{@link String}
	 * @since error 出参|PDF生成结果true/false|{@link String}
	 * @return 0 失败<br/>
	 *         1 成功<br/>
	 * @throws DocumentException 
	 * @throws IOException 
	 */
	@Override
	public boolean createBasePdf(JSONObject json) throws Exception {
		//AppLogger.info("业务日期---------：" + busi_date);
		//AppLogger.info("函证编号---------：" + confirmno);
		//AppLogger.info("会计师事务所名称---------：" + tenantname);
		//AppLogger.info("起始日期---------：" + startdate);
		//AppLogger.info("截止日期---------：" + enddate);
		//AppLogger.info("单位名称---------：" + organizationname);
		//AppLogger.info("函证项信息---------：" + String.valueOf(values));
		
		//*************************生成PDF文件
		//AppLogger.info("*************************生成PDF文件start");
		String hzbh = (String) json.get("hzbh");//函证编号
		String recvdate = (String) json.get("recvdate");//函证接收日期
		String organizationname = (String) json.get("organizationname");//单位名称
		String tenantname = (String) json.get("tenantname");//会计师事务所名称
		System.out.print("函证编号---------：" + hzbh);
		System.out.print("函证编号---------：" + json);
		
		String confirmbegindate = (String) json.get("confirmbegindate");//起始日期
		String confirmenddate = (String) json.get("confirmenddate");//截止日期
		
		String sendhzno = (String) json.get("sendhzno");//20240710发函编号
		
		String pdffilepath = (String) json.get("pdffilepath");
		String finishdate = (String) json.get("finishdate");
		
//		Date Date = new Date();
//		SimpleDateFormat format_s = new SimpleDateFormat("yyyyMMdd");
		String workdate=finishdate;
		//String workdate = (String) json.get("workdate");
		
		String agent = (String) json.get("agent");//经办人
		String reviewer = (String) json.get("reviewer");//审核人
		
		//页面大小
		String startdate;
		String busi_date = null;
		Rectangle rect = new Rectangle(PageSize.A4);//文档竖向
//		String outputfilePath = "C:/Users/A9010012/Desktop";
		//String outputfilePath = pdffilepath+hzbh+"_0.pdf";
		
		String flag = (String) json.get("flag");//文件目录
		String outputfilePath = "";
		if(flag.equals("update")){
			outputfilePath = pdffilepath+"(update)"+hzbh+"(CTP).pdf";
		}else{
			outputfilePath = pdffilepath+hzbh+"(CTP).pdf";
		}
		
		Document doc = null;
		PdfWriter writer= null;
		try{
			//如果没有则创建
			File saveDir = new File(outputfilePath);
			File dir = saveDir.getParentFile();
			if(!dir.exists()){
				dir.mkdirs();			
			}
			doc = new Document(rect);
			writer= PdfWriter.getInstance(doc, new FileOutputStream(outputfilePath));
			//writer.setViewerPreferences(PdfWriter.PageLayoutOneColumn);
			//writer.setPageEvent(new PdfPageEventHelper());
			//PDF版本（默认1.4）
			writer.setPdfVersion(PdfWriter.VERSION_1_7);
			//页边空白	
			doc.setMargins(40, 40, 40, 40);
			//打开文档
			doc.open();
			
			//AppLogger.info("-***********************生成PDF文件end");
			//*********************************************添加PDF文件头
			//doc.add(getFont(6, "Confidential 机密"));
			//doc.add(getFont(6, "Confidential 机密                                                                                          "+"发函编号："+sendhzno));
			//doc.add(getFont(6, "Confidential 机密"));
			doc.add(getFont(1, "银行询证函"));
			//doc.add(getFont(4, "编号："+hzbh));
			doc.add(getFont(3, tenantname+"会计师事务所："));
			doc.add(getFont(3, "贵方编号："+sendhzno));
			doc.add(getFont(3, "我行编号："+hzbh));
			doc.add(getFont(3, "截至"+confirmenddate+"，"+organizationname+"单位的询证信息如下："));
			
//			boolean flag_6 = false;
//			List values = new ArrayList();
//			values.add("1");

			if(json != null && !json.equals("{}")){
				PdfPTable table = null;
//				List result = null;
				//银行存款函证
				List bankdeposit_colName = Arrays.asList("账户名称","银行账号","币种","利率","账户类型","账户余额","是否属于资金归集（资金池或其他资金管理）账户","起始日期","终止日期","是否存在冻结、担保或其他使用限制（如是，请注明相关情形）","备注");
				//银行借款函证
				List bankloan_colName = Arrays.asList("借款人名称","借款账号","币种","余额","借款日期","到期日期","利率","抵（质）押品/担保人","备注");
				//期间注销账户函证
				List closeacctno_colName = Arrays.asList("账户名称","银行账号","币种","注销账户日");
				//公司贷款方委托贷款函证
				List creditloan_colName = Arrays.asList("账户名称","银行结算账号/借据编号/贷款账号","资金借入方","币种","利率","余额","贷款起止日期","备注");
				//公司借款方委托贷款函证
				List debtorloan_colName = Arrays.asList("账户名称","银行结算账号/借据编号/贷款账号","资金借出方","币种","利率","余额","贷款起止日期","备注");
				//银行受益人担保函证
				List ensurefavoree_colName = Arrays.asList("被担保人","担保方式","币种","担保余额","担保到期日","担保合同编号","备注");
				//银行担保函证
				List givesecurity_colName = Arrays.asList("被担保人","担保方式","币种","担保金额","担保到期日","担保合同编号","备注");
				//未支付银行承兑汇票函证
				List unpaidaccance_colName = Arrays.asList("银行承兑汇票号码","结算账户账号","币种","票面金额","出票日","到期日","抵（质）押品");
				//未到期商业汇票函证
				List notduetradebill_colName = Arrays.asList("商业汇票号码","承兑人名称","币种","票面金额","出票日","到期日","贴现日","贴现率","贴现净额");
				//银行托收商业汇票函证
				List colltradebill_colName = Arrays.asList("商业汇票号码","承兑人名称","币种","票面金额","出票日","到期日");
				//不可撤销信用证函证
				List irrofcredit_colName = Arrays.asList("信用证号码","受益人","币种","信用证金额","到期日","未使用金额");
				//外汇买卖合约函证
				List foreigndealcon_colName = Arrays.asList("类    别","合约号码","贵行卖出币种","贵行买入币种","未履行的合约买卖金额","汇率","交收日期");
				//证券产权文件函证
				List secquityfile_colName = Arrays.asList("证券或其他产权文件名称","证券代码或产权文件编号","数量","币种","金额");
				//未到期银行理财产品函证
				List notduefinalpro_colName = Arrays.asList("产品名称","产品类型（封闭式/开放式）","币种","持有份额","产品净值","购买日","到期日","是否被用于担保或存在其他使用限制");
				//资金归集账户信息函证
				List cashconacctinfo_colName = Arrays.asList("序号","资金提供机构名称(即拨入资金的具体机构)","资金提供机构账号","资金使用机构名称(即向该具体机构拨出资金)","资金使用机构账号","币种","截至函证基准日拨入或拨出资金余额(拨出填列正数，拨入填列负数)","备注");
				//其他函证
				List otherinfo_colName = Arrays.asList("无");
				
				//其他函证1
				List otherinfo1_colName = Arrays.asList("客户名称","类别","合约号码","贵行支付币种","贵行收取币种","未履行的合约金额","到期日");
				//其他函证2
				List otherinfo2_colName = Arrays.asList("客户名称","类别","合约号码","期权结构","未履行的合约币种","未履行的合约金额","行权价格","到期日");
				//其他函证3
				List otherinfo3_colName = Arrays.asList("客户名称","类别","合约号码","贵行支付利率","贵行收取利率","未履行的合约币种","未履行的合约金额","到期日");
				//其他函证4
				List otherinfo4_colName = Arrays.asList("客户名称","类别","合约号码","期权结构","未履行的合约币种","未履行的合约金额","行权价格","到期日");
				
				//其他函证5
				List otherinfo5_colName = Arrays.asList("借款人名称","借款账号","币种","余额","借款日期","到期日期","利率","抵(质)押品担保人","备注");
				
				//其他函证6
				List otherinfo6_colName = Arrays.asList("除上述列示的其他信息外，本行补充以下信息");
				
				System.out.print(json.get("bankdeposit_num"));
				
				for (int i = 0; i < (int)json.get("hzxnum"); i++) {
					List a = (List)json.get("hzxinfo");
					
//					System.out.print("******"+a.get(i).toString().replace("[", "").replace("]", "").replace("\"", ""));
//					System.out.print("******"+a.get(i).toString().replace("[", "").replace("]", "").replace("\"", ""));
//					switch(a.get(i).toString().replace("[", "").replace("]", "").replace("\"", "")){
					switch(a.get(i).toString()){
						case "[\"1\"]":
							if((int)json.get("bankdeposit_num") > 0){
								List result = (List)json.get("bankdeposit");
								System.out.print(result.toString());
								table = tableTemplates(result,bankdeposit_colName);
								doc.add(getFont(3, "1.银行存款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行存款（包括余额为零的存款账户）外，本公司并无在贵行的其他存款。"));	
							}else if((int)json.get("bankdeposit_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < bankdeposit_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								table = tableTemplates(result,bankdeposit_colName);
								doc.add(getFont(3, "1.银行存款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行存款（包括余额为零的存款账户）外，本公司并无在贵行的其他存款。"));
							}
						break;
						case "[\"2\"]":
							if((int)json.get("bankloan_num") > 0){
								List result = (List)json.get("bankloan");
								System.out.print(result.toString());
								table = tableTemplates(result,bankloan_colName);
								doc.add(getFont(3, "2.银行借款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行借款外，本公司并无自贵行的其他借款。"));	
							}else if((int)json.get("bankloan_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < bankloan_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print("=========="+result);
								table = tableTemplates(result,bankloan_colName);
								doc.add(getFont(3, "2.银行借款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行借款外，本公司并无自贵行的其他借款。"));
							}
						break;
						case "[\"3\"]":
							if((int)json.get("closeacctno_num") > 0){
								String begdate = DateUtil.formatDate(confirmbegindate, "yyyymmdd", "yyyy年mm月dd日");
								String enddate = DateUtil.formatDate(confirmenddate, "yyyymmdd", "yyyy年mm月dd日");
								List result = (List)json.get("closeacctno");
								table = tableTemplates(result,closeacctno_colName);
								doc.add(getFont(3, "3.自"+begdate+"起至"+enddate+"期间内注销的银行存款账户"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的注销账户外，本公司在此期间并未在贵行注销其他账户。"));	
							}else if((int)json.get("closeacctno_num") == 0){
								String begdate = DateUtil.formatDate(confirmbegindate, "yyyymmdd", "yyyy年mm月dd日");
								String enddate = DateUtil.formatDate(confirmenddate, "yyyymmdd", "yyyy年mm月dd日");
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < closeacctno_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,closeacctno_colName);
								doc.add(getFont(3, "3.自"+begdate+"起至"+enddate+"期间内注销的银行存款账户"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的注销账户外，本公司在此期间并未在贵行注销其他账户。"));
							}
						break;
						case "[\"4\"]":
							if((int)json.get("creditloan_num") > 0){
								
								List result = (List)json.get("creditloan");
								table = tableTemplates(result,creditloan_colName);
								doc.add(getFont(3, "4.本公司作为委托人的委托贷款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的委托贷款外，本公司并无通过贵行办理的其他以本公司作为委托人的委托贷款。"));	
							}else if((int)json.get("creditloan_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < creditloan_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,creditloan_colName);
								doc.add(getFont(3, "4.本公司作为委托人的委托贷款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的委托贷款外，本公司并无通过贵行办理的其他以本公司作为委托人的委托贷款。"));
							}
						break;
						case "[\"5\"]":
							if((int)json.get("debtorloan_num") > 0){
								
								List result = (List)json.get("debtorloan");
								table = tableTemplates(result,debtorloan_colName);
								doc.add(getFont(3, "5.本公司作为借款人的委托贷款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的委托贷款外，本公司并无通过贵行办理的其他以本公司作为借款人的委托贷款。"));	
							}else if((int)json.get("debtorloan_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < debtorloan_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,debtorloan_colName);
								doc.add(getFont(3, "5.本公司作为借款人的委托贷款"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的委托贷款外，本公司并无通过贵行办理的其他以本公司作为借款人的委托贷款。"));
							}
						break;
						case "[\"6.1\"]":
							if((int)json.get("ensurefavoree_num") > 0){
								
								List result = (List)json.get("ensurefavoree");
								table = tableTemplates(result,ensurefavoree_colName);
								doc.add(getFont(3, "6.担保"));
					      		doc.add(getFont(3, "（1）本公司为其他单位提供的、以贵行为担保受益人的担保"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的担保外，本公司并无其他以贵行为担保受益人的担保。"));	
							}else if((int)json.get("ensurefavoree_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < ensurefavoree_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,ensurefavoree_colName);
								doc.add(getFont(3, "6.担保"));
					      		doc.add(getFont(3, "（1）本公司为其他单位提供的、以贵行为担保受益人的担保"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的担保外，本公司并无其他以贵行为担保受益人的担保。"));
							}
						break;
						case "[\"6.2\"]":
							if((int)json.get("givesecurity_num") > 0){
								
								List result = (List)json.get("givesecurity");
								table = tableTemplates(result,givesecurity_colName);
								doc.add(getFont(3, "6.担保"));
					       		doc.add(getFont(3, "（2）贵行向本公司提供的担保（如保函业务、备用信用证业务等）")); 
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的担保外，本公司并无贵行提供的其他担保。"));	
							}else if((int)json.get("givesecurity_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < givesecurity_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,givesecurity_colName);
								doc.add(getFont(3, "6.担保"));
					       		doc.add(getFont(3, "（2）贵行向本公司提供的担保（如保函业务、备用信用证业务等）")); 
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的担保外，本公司并无贵行提供的其他担保。"));
							}
						break;
						case "[\"7\"]":
							if((int)json.get("unpaidaccance_num") > 0){
								
								List result = (List)json.get("unpaidaccance");
								table = tableTemplates(result,unpaidaccance_colName);
								doc.add(getFont(3, "7.本公司为出票人且由贵行承兑而尚未支付的银行承兑汇票"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行承兑汇票外，本公司并无由贵行承兑而尚未支付的其他银行承兑汇票。"));	
							}else if((int)json.get("unpaidaccance_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < unpaidaccance_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,unpaidaccance_colName);
								doc.add(getFont(3, "7.本公司为出票人且由贵行承兑而尚未支付的银行承兑汇票"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行承兑汇票外，本公司并无由贵行承兑而尚未支付的其他银行承兑汇票。"));
							}
						break;
						case "[\"8\"]":
							if((int)json.get("notduetradebill_num") > 0){
								
								List result = (List)json.get("notduetradebill");
								table = tableTemplates(result,notduetradebill_colName);
								doc.add(getFont(3, "8.本公司向贵行已贴现而尚未到期的商业汇票"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的商业汇票外，本公司并无向贵行已贴现而尚未到期的其他商业汇票。"));	
							}else if((int)json.get("notduetradebill_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < notduetradebill_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,notduetradebill_colName);
								doc.add(getFont(3, "8.本公司向贵行已贴现而尚未到期的商业汇票"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的商业汇票外，本公司并无向贵行已贴现而尚未到期的其他商业汇票。"));
							}
						break;
						case "[\"9\"]":
							if((int)json.get("colltradebill_num") > 0){
								
								List result = (List)json.get("colltradebill");
								table = tableTemplates(result,colltradebill_colName);
								doc.add(getFont(3, "9.本公司为持票人且由贵行托收（或由本公司提示付款）的商业汇票"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的商业汇票外，本公司并无由贵行托收的其他商业汇票。"));	
							}else if((int)json.get("colltradebill_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < colltradebill_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,colltradebill_colName);
								doc.add(getFont(3, "9.本公司为持票人且由贵行托收（或由本公司提示付款）的商业汇票"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的商业汇票外，本公司并无由贵行托收的其他商业汇票。"));
							}
						break;
						case "[\"10\"]":
							if((int)json.get("irrofcredit_num") > 0){
								
								List result = (List)json.get("irrofcredit");
								table = tableTemplates(result,irrofcredit_colName);
								doc.add(getFont(3, "10.本公司为申请人，由贵行开具的、未履行完毕的不可撤销信用证"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的不可撤销信用证外，本公司并无由贵行开具的、未履行完毕的其他不可撤销信用证。"));	
							}else if((int)json.get("irrofcredit_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < irrofcredit_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,irrofcredit_colName);
								doc.add(getFont(3, "10.本公司为申请人，由贵行开具的、未履行完毕的不可撤销信用证"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的不可撤销信用证外，本公司并无由贵行开具的、未履行完毕的其他不可撤销信用证。"));
							}
						break;
						case "[\"11\"]":
							if((int)json.get("foreigndealcon_num") > 0){
								
								List result = (List)json.get("foreigndealcon");
								table = tableTemplates(result,foreigndealcon_colName);
								doc.add(getFont(3, "11.本公司与贵行之间未履行完毕的外汇买卖合约"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的外汇买卖合约外，本公司并无与贵行之间未履行完毕的其他外汇买卖合约。"));	
							}else if((int)json.get("foreigndealcon_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < foreigndealcon_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,foreigndealcon_colName);
								doc.add(getFont(3, "11.本公司与贵行之间未履行完毕的外汇买卖合约"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的外汇买卖合约外，本公司并无与贵行之间未履行完毕的其他外汇买卖合约。"));
							}
						break;
						case "[\"12\"]":
							if((int)json.get("secquityfile_num") > 0){
								
								List result = (List)json.get("secquityfile");
								table = tableTemplates(result,secquityfile_colName);
								doc.add(getFont(3, "12.本公司存放于贵行托管的证券或其他产权文件"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的证券或其他产权文件外，本公司并无存放于贵行托管的其他证券或其他产权文件。"));	
							}else if((int)json.get("secquityfile_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < secquityfile_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,secquityfile_colName);
								doc.add(getFont(3, "12.本公司存放于贵行托管的证券或其他产权文件"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的证券或其他产权文件外，本公司并无存放于贵行托管的其他证券或其他产权文件。"));
							}
						break;
						case "[\"13\"]":
							if((int)json.get("notduefinalpro_num") > 0){
								
								List result = (List)json.get("notduefinalpro");
								table = tableTemplates(result,notduefinalpro_colName);
								doc.add(getFont(3, "13.本公司购买的由贵行发行的未到期银行理财产品"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行理财产品外，本公司并未购买其他由贵行发行的理财产品。"));	
							}else if((int)json.get("notduefinalpro_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < notduefinalpro_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,notduefinalpro_colName);
								doc.add(getFont(3, "13.本公司购买的由贵行发行的未到期银行理财产品"));
								doc.add(table);
					       		//doc.add(getFont(2, "除上述列示的银行理财产品外，本公司并未购买其他由贵行发行的理财产品。"));
							}
						break;
						case "[\"14\"]":
							if((int)json.get("otherinfo_num") > 0){
								List result = (List)json.get("otherinfo");
								table = tableTemplates(result,otherinfo_colName);
								doc.add(getFont(3, "14.其他"));
								doc.add(table);
								
							}else if((int)json.get("otherinfo_num") == 0){
								PdfPTable table_other = null;
								PdfPTable table_other_none = null;
								
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < otherinfo_colName.size()+1; j++) {
									li.add("	");
								}
								result.add(li);
								List result_zore = new ArrayList();
								List li_zore = new ArrayList();
								for (int j = 1; j < otherinfo_colName.size()+1; j++) {
									li_zore.add("无");
								}
								result_zore.add(li_zore);
//								List result_none = new ArrayList();
//								List li_none = new ArrayList();
//								for (int j = 1; j < otherinfo_colName.size()+1; j++) {
//									li_none.add("无");
//								}
//								result.add(li);
								
								table_other_none = tableTemplates(result,otherinfo_colName);
								doc.add(getFont(3, "14.其他"));
								//doc.add(table_other);
								if((int)json.get("otherinfo1_num") == 0 && (int)json.get("otherinfo2_num") == 0 && (int)json.get("otherinfo3_num") == 0 && (int)json.get("otherinfo4_num") == 0 && (int)json.get("otherinfo5_num") == 0 && (int)json.get("otherinfo6_num") == 0){
									table_other = tableTemplates(result_zore,otherinfo_colName);
									doc.add(table_other);
								}else{
									if((int)json.get("otherinfo1_num") > 0){
										List result1 = (List)json.get("otherinfo1");
										table_other = tableTemplates(result1,otherinfo1_colName);
										doc.add(table_other);
									}else if((int)json.get("otherinfo1_num") == 0){
										List result_otherinfo1 = new ArrayList();
										List result1 = new ArrayList();
										List li1 = new ArrayList();
										for (int j = 1; j < otherinfo1_colName.size()+1; j++) {
											li1.add("无");
										}
										result1.add(li1);
										table_other = tableTemplates(result1,otherinfo1_colName);
										doc.add(table_other);
										
									}
									doc.add(table_other_none);
									if((int)json.get("otherinfo2_num") > 0){
										List result2 = (List)json.get("otherinfo2");
										table_other = tableTemplates(result2,otherinfo2_colName);
										doc.add(table_other);
									}else if((int)json.get("otherinfo2_num") == 0){
										List result_otherinfo2 = new ArrayList();
										List result2 = new ArrayList();
										List li2 = new ArrayList();
										for (int j = 1; j < otherinfo2_colName.size()+1; j++) {
											li2.add("无");
										}
										result2.add(li2);
										table_other = tableTemplates(result2,otherinfo2_colName);
										doc.add(table_other);
									}
									doc.add(table_other_none);
									if((int)json.get("otherinfo3_num") > 0){
										List result3 = (List)json.get("otherinfo3");
										table_other = tableTemplates(result3,otherinfo3_colName);
										doc.add(table_other);
									}else if((int)json.get("otherinfo3_num") == 0){
										List result_otherinfo3 = new ArrayList();
										List result3 = new ArrayList();
										List li3 = new ArrayList();
										for (int j = 1; j < otherinfo3_colName.size()+1; j++) {
											li3.add("无");
										}
										result3.add(li3);
										table_other = tableTemplates(result3,otherinfo3_colName);
										doc.add(table_other);
									}
									doc.add(table_other_none);
									if((int)json.get("otherinfo4_num") > 0){
										List result4 = (List)json.get("otherinfo4");
										table_other = tableTemplates(result4,otherinfo4_colName);
										doc.add(table_other);
									}else if((int)json.get("otherinfo4_num") == 0){
										List result_otherinfo4 = new ArrayList();
										List result4 = new ArrayList();
										List li4 = new ArrayList();
										for (int j = 1; j < otherinfo4_colName.size()+1; j++) {
											li4.add("无");
										}
										result4.add(li4);
										table_other = tableTemplates(result4,otherinfo4_colName);
										doc.add(table_other);
									}
									doc.add(table_other_none);
									if((int)json.get("otherinfo5_num") > 0){
										List result5 = (List)json.get("otherinfo5");
										table_other = tableTemplates(result5,otherinfo5_colName);
										doc.add(table_other);
									}else if((int)json.get("otherinfo5_num") == 0){
										List result_otherinfo5 = new ArrayList();
										List result5 = new ArrayList();
										List li5 = new ArrayList();
										for (int j = 1; j < otherinfo5_colName.size()+1; j++) {
											li5.add("无");
										}
										result5.add(li5);
										table_other = tableTemplates(result5,otherinfo5_colName);
										doc.add(table_other);
									}
									doc.add(table_other_none);
									if((int)json.get("otherinfo6_num") > 0){
										List result6 = (List)json.get("otherinfo6");
										table_other = tableTemplates(result6,otherinfo6_colName);
										doc.add(table_other);
									}else if((int)json.get("otherinfo6_num") == 0){
										List result_otherinfo6 = new ArrayList();
										List result6 = new ArrayList();
										List li6 = new ArrayList();
										for (int j = 1; j < otherinfo6_colName.size()+1; j++) {
											li6.add("无");
										}
										result6.add(li6);
										table_other = tableTemplates(result6,otherinfo6_colName);
										doc.add(table_other);
									}	
								}
								
								
								
								
								
								
//					       		doc.add(getFont(2, "除上述列示的委托贷款外，本公司并无通过贵行办理的其他以本公司作为委托人的委托贷款。"));
							}
						break;
						case "[\"15\"]":
							if((int)json.get("cashconacctinfo_num") > 0){
								
								List result = (List)json.get("cashconacctinfo");
								table = tableTemplates(result,cashconacctinfo_colName);
								doc.add(getFont(3, "附表.资金归集(资金池或其他资金管理)账户具体信息"));
								doc.add(table);
//					       		doc.add(getFont(2, "除上述列示的委托贷款外，本公司并无通过贵行办理的其他以本公司作为委托人的委托贷款。"));	
							}else if((int)json.get("cashconacctinfo_num") == 0){
								List result = new ArrayList();
								List li = new ArrayList();
								for (int j = 1; j < cashconacctinfo_colName.size()+1; j++) {
									li.add("无");
								}
								result.add(li);
								System.out.print(result.toString());
								table = tableTemplates(result,cashconacctinfo_colName);
								doc.add(getFont(3, "附表.资金归集(资金池或其他资金管理)账户具体信息"));
								doc.add(table);
//					       		doc.add(getFont(2, "除上述列示的委托贷款外，本公司并无通过贵行办理的其他以本公司作为委托人的委托贷款。"));
							}
						break;
					}

					
				}
			}
			//doc.add(getFont(5, "\r\n\r\n\r\n"));
			doc.add(getFont(5, "\r\n\r\n"));
	        //doc.add(getFont(5, "银行签章（加盖电子业务专用章）\r\n\r\n"));
	        //doc.add(getFont(5, "银行签章（加盖询证函业务专用章）\r\n\r\n"));
	        //workdate = "";
	        //doc.add(getFont(5, "签署日期："+workdate+"\r\n"));
//	      doc.add(getFont(5, "二维码（验证函证内容）"));
	        
	       // createFooter(pdffilepath+hzbh+".pdf",pdffilepath+hzbh+"_1.pdf");
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			doc.close();
	        writer.close();
		}
		

        
		return true;	
				
	}
	

	
	public boolean createFooter(String pdfPath,String newfile){
		boolean retValue = false;
		Document doc = null;
		PdfReader reader = null;
		PdfCopy copy = null;
		try{
			 doc = new Document(new PdfReader(pdfPath).getPageSize(1));
			 reader = new PdfReader(pdfPath);
			 copy = new PdfCopy(doc,new FileOutputStream(newfile));
			 doc.open();
			 int pagesNum=0;
			 int pages=0;
			 
			 pagesNum+=reader.getNumberOfPages();
			 PdfCopy.PageStamp stamp;
			 int n = reader.getNumberOfPages();
			 for(int j = 1;j <= n;j++){
					pages++;
					doc.newPage();
					PdfImportedPage page = copy.getImportedPage(reader, j);
					stamp = copy.createPageStamp(page);
//					PdfContentByte pdf = stamp.getUnderContent();
//					Phrase p = new Phrase(getFont(2,String.format("第%d页/共%d页", pages, pagesNum)));
//					int alignment = Element.ALIGN_CENTER;
					if(pages==n){
						/**说明：
						1、基于客户的询证需求，我行按贵方来函询证项目进行回函，如有疑问，请及时与我行联系。
						2、本询证函回函中所列信息应严格保密，仅用于来函指定目的，我行不承担任何形式的担保责任。**/
						ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_CENTER, new Phrase(getFont(2,"说明：")), 40, 80, 0);
						ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_CENTER, new Phrase(getFont(2,"1、基于客户的询证需求，我行按贵方来函询证项目进行回函，如有疑问，请及时与我行联系。")), 245, 60, 0);
						ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_CENTER, new Phrase(getFont(2,"2、本询证函回函中所列信息应严格保密，仅用于来函指定目的，我行不承担任何形式的担保责任。")), 255, 40, 0);
						//ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_CENTER, new Phrase(getFont(2,String.format("第%d页/共%d页", pages, pagesNum))), 500, 20, 0);
						ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_RIGHT, new Phrase(getFont(4,String.format("Confidential 机密                              第%d页/共%d页", pages, pagesNum))), 560, 10, 0);
						stamp.alterContents();
						copy.addPage(page);
					}else{
						ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_RIGHT, new Phrase(getFont(4,String.format("Confidential 机密                              第%d页/共%d页", pages, pagesNum))), 560, 10, 0);
						//ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_CENTER, new Phrase(getFont(2,String.format("第%d页/共%d页", pages, pagesNum))), 500, 20, 0);
						stamp.alterContents();
						copy.addPage(page);
					}
					
					
				}
			 
			 retValue = true;
		}catch(IOException e){
			e.printStackTrace();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			reader.close();
			copy.close();
			doc.close();
		}
		return retValue;
		 
	        
	       
	}
	
	public boolean renameToPdf(String pdfPath,String newfile) throws Exception{
		File pdfFile = new File(pdfPath);
	    String pdfName = pdfFile.getName();
		String tmpName = pdfName.substring(0, pdfName.lastIndexOf("."));
	    String filePatch2 = new File(pdfFile.getParentFile(), tmpName
				+ "_" + 2 + ".pdf").getAbsolutePath();
	    String filePatch = new File(pdfFile.getParentFile(), tmpName
				+ ".pdf").getAbsolutePath();
	    String filePatch1 = new File(pdfFile.getParentFile(), tmpName
				+ "_" + 1 + ".pdf").getAbsolutePath();
	    String filePatch0 = new File(pdfFile.getParentFile(), tmpName
				+ "_" + 0 + ".pdf").getAbsolutePath();
	    String filePatch3 = new File(pdfFile.getParentFile(), tmpName
				+ ".jpg").getAbsolutePath();
	    File pdfFile2 = new File(filePatch2);
	    File pdfFile1 = new File(filePatch1);
	    File pdfFile3 = new File(filePatch3);
	    File pdfFile0 = new File(filePatch0);
	    FileUtils.copyFile(pdfFile, pdfFile2);
//	    pdfFile.delete();
	    //FileUtils.fileDelete(pdfPath);
	    //FileUtils.rename(from, to);
	    //pdfFile3.renameTo(pdfFile2);
	    //pdfFile2.deleteOnExit();
		//boolean flag = pdfFile.renameTo(pdfFile2);
	    //FileUtils.rename(pdfFile, pdfFile2);
	    
	   // System.out.print("修改原始文件名"+flag);
		boolean flag2 = pdfFile1.renameTo(pdfFile);
		System.out.print("还原文件名"+flag2);
		//boolean flag1 = new File(filePatch1).renameTo(new File(filePatch));
		return true;
	}
	
	

	private Paragraph getFont(int type,String text) throws DocumentException, IOException{
		//AppLogger.info("进入字体控制----------------"+type+text);
		BaseFont baseFont = BaseFont.createFont("C:/Windows/Fonts/simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
		Font font = new Font(baseFont);
		font.setFamily("仿宋_GB2312");
		if(1 == type){//银行询证函
			font.setSize(16f);
			font.setStyle(Font.BOLD);
		}else if(2 == type){//正文
			font.setSize(10.5f);		
		}else if(3 == type){//左对齐
			font.setSize(10.5f);	
		}else if(4 == type){//右对齐
			font.setSize(10.5f);
		}else if(5 == type){//右对齐加粗
			font.setSize(9f);
			font.setStyle(Font.BOLD);
		}else if(6 == type){//confidential 机密
			font.setSize(6.5f);
			font.setStyle(Font.BOLD);
		}else{
			font.setSize(10.5f);			
		}
		
		Paragraph paragraph = new Paragraph(text,font);
		if(1 == type){
			paragraph.setAlignment(Paragraph.ALIGN_CENTER);//居中
			paragraph.setSpacingBefore(5f);//上间距
			paragraph.setSpacingAfter(10f);//下间距
		}else if(2 == type){
			paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
			paragraph.setFirstLineIndent(24);
			paragraph.setSpacingBefore(5f);
			paragraph.setSpacingAfter(10f);
		}else if(3 == type){
			paragraph.setAlignment(Element.ALIGN_LEFT);
			paragraph.setSpacingBefore(5f);
			paragraph.setSpacingAfter(5f);
		}else if(4 == type){
			paragraph.setAlignment(Element.ALIGN_RIGHT);
			paragraph.setSpacingBefore(5f);
			paragraph.setSpacingAfter(5f);
		}else if(5 == type){
			paragraph.setAlignment(Element.ALIGN_RIGHT);
			paragraph.setSpacingBefore(5f);
			paragraph.setSpacingAfter(10f);
		}else if(6 == type){
			paragraph.setAlignment(Element.ALIGN_CENTER);
		}
		return paragraph;
	}
	
	
	private PdfPTable tableTemplates(List items,List colName) throws DocumentException, IOException{
		//AppLogger.info("***********************表格模板开始");
		PdfPTable inttable = new PdfPTable(colName.size());
		inttable.setWidthPercentage(100);//表格100%宽度填充
		inttable.setLockedWidth(false);//不固定宽度
		
		inttable.getDefaultCell().setLeading(1f, 1f);//单元格内文字行间距
		inttable.getDefaultCell().setBorderColor(new BaseColor(0, 0, 0));//边框颜色

		inttable.getDefaultCell().setUseAscender(true);//设置可以居中
		inttable.getDefaultCell().setMinimumHeight(20);////单元格内文字不确定个，不能设置成固定行高
//		inttable.setHeaderRows(1);//第一行做表头 会导致每一页开头都有表头
		inttable.setSplitLate(false);
		inttable.setSplitRows(true);
		
		if(colName.size() != 1){
			//表头
			for(int i=0; i<colName.size();i++){
				inttable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);//设置水平居中
				inttable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);//设置垂直居中
				inttable.addCell(new Paragraph((String) colName.get(i),getTableFont()));
			}
			
			//表格每行
			for(int i=0; i < items.size(); i++){
				for(int j=0; j<((List)items.get(i)).size(); j++){
	                if(j == 0){
	                	inttable.getDefaultCell().setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);                	
	                }else{
	                	inttable.getDefaultCell().setBorder(Rectangle.RIGHT | Rectangle.BOTTOM); 
	                }				
					if(j < colName.size()){	
						inttable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);//设置水平居中
						inttable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);//设置垂直居中
						inttable.addCell(new Paragraph(((List)items.get(i)).get(j).toString(),getTableFont()));
					}
				}
			}
			
		}else if(colName.size() == 1){
//			inttable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);//设置水平居中
//			inttable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);//设置垂直居中
//			inttable.addCell(new Paragraph("无",getTableFont()));
			if(colName.get(0).equals("无")){
				
				inttable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);//设置水平居中
				inttable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);//设置垂直居中
				inttable.addCell(new Paragraph(((List)items.get(0)).get(0).toString(),getTableFont()));
				logger.info("打印无的内容1："+((List)items.get(0)).get(0).toString());
				
			
			}else if(colName.get(0).equals("除上述列示的其他信息外，本行补充以下信息")){
				
				inttable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);//设置水平居中
				inttable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);//设置垂直居中
				inttable.addCell(new Paragraph((String) colName.get(0),getTableFont()));
				logger.info("打印无的内容2："+(String) colName.get(0));
				
				inttable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);//设置水平居中
				inttable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);//设置垂直居中
				inttable.addCell(new Paragraph(((List)items.get(0)).get(0).toString(),getTableFont()));
				
			}else{
				inttable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);//设置水平居中
				inttable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);//设置垂直居中
				inttable.addCell(new Paragraph((String) colName.get(0),getTableFont()));
				logger.info("打印无的内容3："+(String) colName.get(0));
			
				inttable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);//设置水平居中
				inttable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);//设置垂直居中
				inttable.addCell(new Paragraph(((List)items.get(0)).get(0).toString(),getTableFont()));
				logger.info("打印无的内容3："+((List)items.get(0)).get(0).toString());
			}
			
			
			
		}else{
//			inttable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);//设置水平居中
//			inttable.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER);//设置垂直居中
//			inttable.addCell(new Paragraph("无",getTableFont()));
			inttable.getDefaultCell().setBorder(Rectangle.TOP | Rectangle.LEFT | Rectangle.RIGHT | Rectangle.BOTTOM);
			inttable.addCell(new Paragraph(((List)items.get(0)).get(0).toString(),getTableFont()));
		}
		//AppLogger.info("***********************表格模板结束");
		return inttable;
		}
	
	
	/**
	 * 设置表格内部字体
	 * @param agrs
	 * @throws IOException 
	 * @throws DocumentException 
	 */
	private Font getTableFont() throws DocumentException, IOException{
		BaseFont baseFont = BaseFont.createFont("C:/Windows/Fonts/simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
		Font font = new Font(baseFont,10f,Font.NORMAL,new BaseColor(0, 0, 0)); 
		font.setFamily("仿宋_GB2312");
		return font;
	}
	
	/**
	 * @category 根据指定内容生成二维码图片
	 * @param qrCodeMsg
	 *            入参|待生成二维码的信息|{@link String}
	 * @param imgPath
	 *            入参|二维码图片路径|{@link String}
	 * @return 0 失败<br/>
	 *         1 成功<br/>
	 */
	/**@InParams(param = {
			@Param(name = "qrCodeMsg", comment = "待生成二维码的信息", type = java.lang.String.class),
			@Param(name = "imgPath", comment = "二维码图片路径，绝对路径，暂只支持jpg文件", type = java.lang.String.class) })
	@Returns(returns = { @Return(id = "0", desp = "失败"),
			@Return(id = "1", desp = "成功") })
	@Component(label = "根据指定内容生成二维码图片", style = "判断型", type = "同步组件", comment = "根据指定内容生成二维码图片", author = "zhuyulin", date = "2021-10-25 09:57:07")**/
	public boolean createQRCodeImage(String qrCodeMsg, String imgPath) {
		try {
			BufferedImage image = createImage(qrCodeMsg, true, 100);
			// mkdirs(imgPath);
			ImageIO.write(image, "JPG", new File(imgPath));
		} catch (Exception e) {
			System.out.print("生成二维码图片发生异常，" + e.getMessage());
			return false;
		}
		return true;
	}
	
	/**
	 * 根据指定内容生成二维码图片
	 * 
	 * @param content
	 *            待生成二维码的内容
	 * @param needCompress
	 *            是否需要压缩
	 * @param qrCodeSize
	 *            二维码图片大小
	 * @return
	 * @throws Exception
	 */
	private BufferedImage createImage(String content,
			boolean needCompress, int qrCodeSize) throws Exception {
		Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
		hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
		hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
		hints.put(EncodeHintType.MARGIN, 0);
		BitMatrix bitMatrix = new MultiFormatWriter().encode(content,
				BarcodeFormat.QR_CODE, qrCodeSize, qrCodeSize, hints);
		int width = bitMatrix.getWidth();
		int height = bitMatrix.getHeight();
		BufferedImage image = new BufferedImage(width, height,
				BufferedImage.TYPE_INT_RGB);
		for (int x = 0; x < width; x++) {
			for (int y = 0; y < height; y++) {
				if(bitMatrix.get(x, y)){
					image.setRGB(x, y, 0xFF000000);
				}else{
					image.setRGB(x, y, 0xFFFFFFFF);
				}
			}
		}
		return image;
	}
	
	
	/**
	 * @category 将图片合成到PDF指定位置
	 * @param qrCodeMsg
	 *            入参|待合成图片的位置集合|
	 *            {@link cn.com.agree.afa.svc.javaengine.context.JavaList}
	 * @param imgPath
	 *            入参|PDF文件路径|{@link String}
	 * @return 0 失败<br/>
	 *         1 成功<br/>
	 */
	/**@InParams(param = {
			@Param(name = "pdfPath", comment = "PDF文件路径，绝对路径", type = java.lang.String.class),
			@Param(name = "imgPath", comment = "待合成图片文件路径，绝对路径", type = java.lang.String.class),
			@Param(name = "pageNo", comment = "PDF文件页码", type = java.lang.Integer.class),
			@Param(name = "positions", comment = "待合成图片的PDF位置集合，一页中如有多个位置需合成图片，列表形式赋值，如：[[x1,y1],[x2,y2],[x3,y3]...]", type = cn.com.agree.afa.svc.javaengine.context.JavaList.class) })
	@Returns(returns = { @Return(id = "0", desp = "失败"),
			@Return(id = "1", desp = "成功") })
	@Component(label = "将图片合成到PDF指定位置", style = "判断型", type = "同步组件", comment = "将图片合成到PDF指定位置", author = "zhuyulin", date = "2021-11-07 10:57:07")**/
	public boolean compositeImageToPDF(String pdfPath,
			String imgPath, Integer pageNo, List<Integer> positions) {
		PdfReader pdfReader = null;
		PdfStamper pdfStamper = null;
		FileOutputStream out = null;
		//String pdfbakpatch="/afabak/ERB/pdf/";
		try {
			File pdfFile = new File(pdfPath);

			pdfReader = new PdfReader(pdfFile.getAbsolutePath());
			int pageNum = pdfReader.getNumberOfPages();
//			pdfReader.getLinks(pageNum);
//			String a = pdfReader.getPageContent(pageNum).toString();
//			pdfReader.getPageN(pageNum);
//			pdfReader.getPdfObject(pageNum);
//			pdfReader.getPdfObjectRelease(pageNum);
			System.out.print("PDF文件页码"+pageNum);
			String pdfName = pdfFile.getName();
			String tmpName = pdfName.substring(0, pdfName.lastIndexOf("."));

			if (pageNo < 1 || pageNo > pageNum) {
				System.out.print("页码超过PDF页数范围【"
						+ pageNo + "】，无法合成");
				return false;
			}
//			AppLogger.info("电子印章合成");
			String tmpPath = new String(pdfPath);
			int index=0;
			for (int i = 0; i < positions.size(); i++) {
				index ++;
//				AppLogger.info("电子印章合成:::"+i);
				PdfReader pdfReader1 = null;
				PdfStamper pdfStamper1 = null;
				FileOutputStream out1 = null;
				try{
					Object position = positions.get(i);
					if (!(position instanceof List)) {
						if (positions.size() < 2) {
							System.out.print("当入参positions列表不是嵌套列表时, 入参列表positions的长度不能小于2");
							return false;
						}
						String tmpPath2 = new File(pdfFile.getParentFile(), tmpName
								+ "_"+index+".pdf").getAbsolutePath();
//						AppLogger.info("tmpPath2:"+tmpPath2);
						pdfReader1 = new PdfReader(tmpPath);
						out1 = new FileOutputStream(tmpPath2);
						pdfStamper1 = new PdfStamper(pdfReader, out1);
						PdfContentByte content = pdfStamper1.getOverContent(pageNo);
						Image image = Image.getInstance(imgPath);
						image.scaleToFit(150, 100);
//						AppLogger.info("合成印章图片开始");
						image.setAbsolutePosition((float) positions.get(0),
								(float) positions.get(1));
						content.addImage(image);
//						AppLogger.info("合成印章图片结束");
						pdfStamper1.close();
						out1.close();
						pdfReader1.close();
						tmpPath = tmpPath2;
						break;
					} else if (((List) position).size() < 2) {
						System.out.print("入参positions列表的子元素的长度不能小于2");
						return false;
					}
					String tmpPath2 = new File(	pdfFile.getParentFile(), tmpName+ "_"+index+".pdf").getAbsolutePath();
//					AppLogger.info("tmpPath2:"+tmpPath2);
					pdfReader1 = new PdfReader(tmpPath);
					out1 = new FileOutputStream(tmpPath2);
					pdfStamper1 = new PdfStamper(pdfReader1, out1);

					List tmpPosition = (List) position;
					PdfContentByte content = pdfStamper1.getOverContent(pageNo);
					Image image = Image.getInstance(imgPath);
					image.scaleToFit(150, 100);
					image.setAbsolutePosition((float) tmpPosition.get(0),(float) tmpPosition.get(1));
					content.addImage(image);
					pdfStamper1.close();
					out1.close();
					pdfReader1.close();
					tmpPath = tmpPath2;
//					AppLogger.info("电子印章合成:::结束");
				}catch (Exception e) {
					System.out.print("电子印章合成到回单PDF文件发生异常，" + e.getMessage());
					return false;
				} finally {
					closeResource(pdfStamper1, out1, pdfReader1);
				}
			}
			pdfReader.close();
			
			if (index > 0) {
				String filePatch0 = new File(pdfFile.getParentFile(), tmpName
						+ "_" + 0 + ".pdf").getAbsolutePath();

				boolean flag = pdfFile.renameTo(new File(filePatch0));

				String filePatch2 = new File(pdfFile.getParentFile(), tmpName
						+ "_" + index + ".pdf").getAbsolutePath();

				boolean flag1 = new File(filePatch2)
				.renameTo(new File(pdfPath));

			}

		} catch (Exception e) {

			System.out.print("图片合成到PDF文件发生异常，" + e.getMessage());
			return false;
		} finally {
			closeResource(pdfStamper, out, pdfReader);
		}
		return true;
	}
	
	private void closeResource(PdfStamper pdfStamper,
			FileOutputStream out, PdfReader pdfReader) {
		try {
			if (pdfStamper != null) {
				pdfStamper.close();
			}
			if (out != null) {
				out.close();
			}
			if (pdfReader != null) {
				pdfReader.close();
			}
		} catch (Exception e) {
//			AppLogger.error("关闭资源发生异常");
//			AppLogger.error(e);
		}
	}
	
	
	public static void main(String[] args) throws Exception {
		BpbcPdfSerevice ca = new BpbcPdfSerevice();
		List<Integer> colName = new ArrayList();
		colName.add(480);
		colName.add(699);
		boolean ss = ca.createQRCodeImage("http://www.baidu.com","C:\\Users\\A9010011\\Desktop\\需求\\c.jpg");
		ca.compositeImageToPDF("C:\\Users\\A9010011\\Desktop\\需求\\c.pdf", "C:\\Users\\A9010011\\Desktop\\需求\\c.jpg", 1, colName);
		System.out.println(ss);
	}
	

}
